package com.tomtop.base.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tomtop.base.dao.CurrencyMapper;
import com.tomtop.base.model.Currency;
import com.tomtop.base.service.CurrencyService;
import com.tomtop.core.datasource.annotation.DataSourceChange;

@Service
public class CurrencyServiceImpl implements CurrencyService {
	
	@Autowired CurrencyMapper currencyMapper;

	@Override	//该方法被调用时不会切换主从库，选中查询数据库由调用者决定， 默认选中主库
	public Currency findById(int id) {
		return currencyMapper.selectByPrimaryKey(id);
	}
	
	@Override
	@DataSourceChange(slave=false)//该方法被调用时，切换到从库查询
	public Currency findByIdOnMaster(int id) {
		return currencyMapper.selectByPrimaryKey(id);
	}

	@Override
	@DataSourceChange(slave=true)//该方法被调用时切换到主库查询
	public Currency findByIdOnSalve(int id) {
		return currencyMapper.selectByPrimaryKey(id);
	}
	
}
